#ifndef WIFI_CONFIG_PAGE_H
#define WIFI_CONFIG_PAGE_H

#include <Arduino.h>

const char wifiConfigPage[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<head>
  <title>WiFi配置</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f5f5f5;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      margin: 0;
      padding: 1rem;
    }
    .wifi-container {
      background: white;
      padding: 2rem;
      border-radius: 8px;
      box-shadow: 0 2px 10px rgba(0,0,0,0.1);
      width: 400px;
      max-width: 100%;
    }
    h1 {
      color: #333;
      margin-bottom: 1.5rem;
      text-align: center;
    }
    .network-list {
      margin: 1rem 0;
      padding: 0;
      list-style: none;
      max-height: 200px;
      overflow-y: auto;
      border: 1px solid #ddd;
      border-radius: 4px;
    }
    .network-item {
      padding: 0.8rem;
      border-bottom: 1px solid #eee;
      cursor: pointer;
      transition: background-color 0.2s;
    }
    .network-item:last-child {
      border-bottom: none;
    }
    .network-item:hover {
      background-color: #f8f9fa;
    }
    input {
      width: 100%;
      padding: 0.8rem;
      margin: 0.5rem 0;
      border: 1px solid #ddd;
      border-radius: 4px;
      box-sizing: border-box;
    }
    button {
      width: 100%;
      padding: 0.8rem;
      margin: 0.5rem 0;
      background-color: #007bff;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-size: 1rem;
      transition: background-color 0.2s;
    }
    button:hover {
      background-color: #0056b3;
    }
    button[type="submit"] {
      background-color: #28a745;
    }
    button[type="submit"]:hover {
      background-color: #218838;
    }
  </style>
</head>
<body>
  <div class="wifi-container">
    <h1>WiFi配置</h1>
    <button onclick="scanNetworks()">扫描WiFi网络</button>
    <ul class="network-list" id="networkList"></ul>
    <form action="/wifi_config" method="POST">
      <input type="text" name="ssid" id="ssidInput" placeholder="请输入WiFi名称" required>
      <input type="password" name="password" placeholder="请输入WiFi密码" required>
      <button type="submit">保存并连接</button>
    </form>
  </div>
  <script>
    function scanNetworks() {
      fetch('/scan')
        .then(response => response.json())
        .then(data => {
          const list = document.getElementById('networkList');
          list.innerHTML = '';
          data.forEach(network => {
            const item = document.createElement('li');
            item.className = 'network-item';
            item.textContent = `${network.ssid} (${network.rssi} dBm)`;
            item.onclick = () => {
              document.getElementById('ssidInput').value = network.ssid;
            };
            list.appendChild(item);
          });
        });
    }
  </script>
</body>
</html>
)=====";

#endif
